-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor options to const #1044
Draft
ankur22
wants to merge
41
commits into
main
Choose a base branch
from
refactor/timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+435
−122
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is where the options or predicate function will be parsed. This aligns with how we're parsing options in other APIs.
This copies the parsing logic from the existing browserContext.waitFor Event() into the new WaitForEventOptions type's parse method. It also modifies it so that the data that is parsed is updated in the type and during parsing it will return an error instead of panicking.
This commit refactors the code so that it works with the new WaitForEventOptions type.
This now defaults to the browserContext's default timeout. This should fix the confusion of mixing seconds and milliseconds when working with the timeouts in this API. NOTE though that there is a default timeout of 30 seconds now, whereas in PW there is no timeout unless one is set explicitly in browserContext using SetDefaultTimeout.
At the moment we only support working with the new page creation event (i.e. "page" event) when waitForEvent is used. This commit helps clarify this to users.
When working with waitForEvent we now notify the user if the timeout was reached, or whether the context is closed (i.e. the test iteration has ended).
Instead of panicking when an error occurs, this commit refactors waitForEvent to return an error back to the mapping layer where it can do what it needs with the error.
This new way of working allows us to test the code with integration tests, and it still works as expected when we run the API through a test script. Before it seemed overly complex to try to create a goja object that required reflection.
It's valid for a user not to pass anything but the event. A change needed to be made to allow for a nil predicate to allow for this.
When a return occurs from runWaitForEventHandler it needs to perform the same steps for all returns out of the method. This refactors those duplicate steps into a defer function.
waitForEvent is useless without it being promisified. This changes that so that waitForEvent returns a promise, allowing the user to set a waitForEvent and then call further APIs which will unblock the waitForEvent when possible (only for new page creations and if the predicate function is set and returns a truthy value).
This helps make things more maintainable and reduces the risk of typos when working with the event types for waitForEvent. Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
This helps tidy up the code and keeps the happy path more left aligned. Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
This just helps make the line lengths of comments consistent.
This not only use a more concise naming convention it also adds '_' to the names, which makes it easier to find tests if they fail. Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
This will help avoid typo issues and make the code more maintainable.
3 tasks
ankur22
force-pushed
the
refactor/wait-for-event
branch
2 times, most recently
from
September 26, 2023 09:23
9c20fdd
to
41b5d7f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This refactors the key strings to consts.
Why?
The main reason is to avoid typos when writing out new option parsers or working with options in other ways. Note thought that I've not done a refactor for all configs, e.g. the options for newContext.
Checklist
Related PR(s)/Issue(s)
Motivated by: comment.